package dilmaj.client;

import java.util.*;

import javax.jdo.annotations.*;

import dilmaj.shared.CommentVO;
import dilmaj.shared.StarEntryVO;
import dilmaj.shared.TermVO;

@PersistenceCapable
public class StarEntryJDO {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    protected Long id;
    
    @Persistent
    protected Long rank;
    
    @Persistent
	protected String caption;
      
    @Persistent
	protected String title;
    
    @Persistent
	protected String description;

    @Persistent
	protected Long userID;

    @Persistent
	protected String userName;
    
    @Persistent
    protected List<Long> attachments=new ArrayList<Long>();
    
    public StarEntryJDO() {
    }
    
    public StarEntryJDO(StarEntryVO starVO) {
    	this.caption=starVO.getCaption();
    	this.title=starVO.getTitle();
    	this.attachments.clear();
    	this.description=starVO.getDescription();
    	this.rank=starVO.getRank();
    	
    	Iterator iterator=starVO.getAttachments().iterator();
    	while (iterator.hasNext()) {
    		StarEntryVO attachVO=(StarEntryVO)iterator.next();
    		attachments.add(attachVO.getId());
    	}
    	
    	if (starVO.getId()!=null)
    		this.id=starVO.getId();
    	
    	userID=starVO.getUserID();
    	userName=starVO.getUsername();
	}

	public String getDescription() {
		return description;
	}
    
    public Long getId() {
    	return id;
    }
    
    public void setId(Long id) {
    	this.id=id;
    }
    
    public String getCaption() {
    	return caption;
    }
    
    public String getTitle() {
    	return title;
    }
    
    public void setCaption(String caption) {
    	this.caption=caption;
    }
    
    public void setTitle(String title) {
    	this.title=title;
    }
    
    public void setRank(Long rank) {
    	this.rank=rank;
    }
    
    public void attach(StarEntryJDO attachment) {
    	attachments.add(attachment.getId());
    }
    
    public void setAttachments(List<Long> newAttachments) {
    	attachments.clear();
    	attachments.addAll(newAttachments);
    }
    
    public void attach(Long id) {
    	attachments.add(id);
    }
    
    public List<Long> getAttachments() {
    	return attachments;
    }
	
	public void setUserName(String username) {
		userName=username;
	}
	
	public void setUserID(Long userid) {
		userID=userid;
	}
	
	public String getUsername() {
		return userName;
	}
	
	public Long getUserID() {
		return userID;
	}
	
	public Long getRank() {
		return rank;
	}
	
	public void setDescription(String description) {
		this.description=description;
	}
	
	public String getAttachmentsAsString() {
		String attachmentString="";
		
		Iterator iterator=attachments.iterator();
		while (iterator.hasNext()) {
			Long currentID=(Long)iterator.next();
			
			attachmentString=attachmentString.concat(Long.toString(currentID.longValue()));
			attachmentString=attachmentString.concat(" ");
		}
		
		return attachmentString;
	}
}
